package com.gemantic.user.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gemantic.user.model.User;
import com.gemantic.user.service.UserService;

/**
*
*
* created by wangshoufa
* 2018年5月23日 下午8:07:42
*
*/
@RestController
@CrossOrigin
@RefreshScope
public class UserController {
	
	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Value("${vals}")
    private String vals;
	
	@Autowired
	private UserService userService;
	
	@GetMapping("/getUser")
	public List<User> getUser() {
		logger.info("profile:" + vals);
		List<User> user = userService.getUser();
		return user;
	}
	
	
	@PostMapping("/updateUser")
	public List<User> updateUser(@RequestParam(required = true) Long id,@RequestParam(required = true) String name) {
		try {
			userService.update(id, name);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return null;
	}
	
	
	@GetMapping("/getInfo")
	public List<User> getInfo() {
		logger.info("env properties value:" + vals);
		List<User> ll = userService.getInfo();
		return ll;
	}
	
	@PostMapping("/deal")
	public void deal(@RequestParam(required = true) Long id,@RequestParam(required = true) String name) {
		boolean resu = false;
		try {
			resu = userService.updateUserByid(id, name);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		logger.info("resu :" + resu);
	}
	
}
